package com.github.yoojia.flow.impl;

import com.github.yoojia.flow.Context;
import com.github.yoojia.flow.Event;
import com.github.yoojia.flow.Payload;
import com.github.yoojia.flow.devices.VirtualPWMDevice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 2017 Yoojia Chen (yoojiachen@gmail.com)
 */
public class PiPWMDevice extends VirtualPWMDevice {

    private static final Logger LOGGER = LoggerFactory.getLogger(PiPWMDevice.class);

    @Override
    public Event handleEvent(Context context, Event request) {
        final Payload.Int value = request.getIntPayload();
        final int pwn = value.int1;
        setPWM(pwn);
        if (isLoggingEnabled()){
            LOGGER.debug("Handling, address: {}, PWM: {} ", getAddress(), pwn);
        }
        return Event.simple(request.sequence, Context.TOPIC_SYS_NORESP);
    }
}
